#region Imported Namespaces
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using PHSRAG.Insight21.InsightUtilities;
using BO = PHSRAG.Insight21.BusinessObjects;
using DataAccess = PHSRAG.Utility.DataAccess;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
using SearchCriteria = PHSRAG.Insight21.SearchContext.SearchCriteria;
using ModuleKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;
#endregion

namespace PHSRAG.Insight21.Agreements
{
	#region FinancialSummaries Public Class
	/// <summary>
	/// Financial Summaries Class retrieves the financial summary resultset and creates from it a
	/// DataView that is used to sort, filter and Total the data.  It returns a resultset made up of
	/// 2 tables.  The first contains the fundIDs and AccessLevels from the original resultset and 
	/// the 2nd contains the totals.
	/// </summary>
	public class FinancialSummaries : BO.BusinessObject
	{
		#region Constants
		private static string	FinancialSummariesKey = ModuleKey.MakeKey("FinancialSummaries", ModuleKey.Agreement);
		#endregion

		#region Private Types
		private enum TableIndex
		{
			IDs, Totals
		}
		#endregion

		#region Instance Variables
		private Hashtable		financialSummaryMap = new Hashtable();
		private bool			includeIndirect = true;
		#endregion

		#region Constructor
		/// <summary>
		/// Initilize the base class with the specified cache policy.
		/// </summary>
		/// <param name="cachePolicy"></param>
		public FinancialSummaries() : base(null)
		{
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Get the key to be used in all caching operations for this instance of the object.
		/// </summary>
		public static string CacheKey	{ get { return FinancialSummariesKey; } }

		/// <summary>Get the total number of agreements.</summary>
		public int Count
		{
			get { return (DataContainer.Tables.Count == 0) ? 0 : DataContainer.Tables[(int)TableIndex.IDs].Rows.Count; }
		}

		/// <summary>Gets the total budget amount displayed in the data grid footer.</summary>
		public decimal TotalBudgetAmount
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalBudgetAmount"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalBudgetAmount"]; }
		}

		/// <summary>Gets the total last month expenses displayed in the data grid footer.</summary>
		public decimal TotalLastMoExpenses
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalLastMoExpenses"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalLastMoExpenses"]; }
		}

		/// <summary>Gets the total expenses to date displayed in the data grid footer.</summary>
		public decimal TotalExpensesToDate
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalExpensesToDate"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalExpensesToDate"]; }
		}

		/// <summary>Gets the total budget balance displayed in the data grid footer.</summary>
		public decimal TotalBudgetBalance
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalBudgetBalance"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalBudgetBalance"]; }
		}

		/// <summary>Gets the total last month expenses displayed in the data grid footer.</summary>
		public decimal TotalRevenue
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalRevenue"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalRevenue"]; }
		}

		/// <summary>Gets the total cash balance displayed in the data grid footer.</summary>
		public decimal TotalCurrentCashBalance
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalCurrentCashBalance"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalCurrentCashBalance"]; }
		}

		/// <summary>Gets the total open PO/AP balance displayed in the data grid footer.</summary>
		public decimal TotalOpenPOAPBalance
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalOpenPOAPBalance"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalOpenPOAPBalance"]; }
		}

		/// <summary>Gets the total planned salary displayed in the dataGrid footer.</summary>
		public decimal TotalPlannedSalary
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalPlannedSalary"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalPlannedSalary"]; }
		}

		/// <summary>Gets the total projected balance displayed in the dataGrid footer.</summary>
		public decimal TotalProjectedBalance
		{
			get { return (DataContainer.Tables.Count == 0 || DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalProjectedBalance"] == DBNull.Value) ? 0 : (decimal)DataContainer.Tables[(int)TableIndex.Totals].Rows[0]["TotalProjectedBalance"]; }
		}
		#endregion

		#region BusinessObject Methods
        private bool IsDate(string sdate)
        {
            try
            {
                DateTime.Parse(sdate);
                return true;
            }
            catch
            {
            }
            return false;
        }

		/// <summary>
		/// Load the current instance with financial summary data for the current user.
		/// </summary>
		/// <param name="connectionString">Database connection string</param>
		/// <param name="args">Is expected to contain a single argument - the domain user ID</param>
		public override void Load(string connectionString, params object[] args)
		{				
			const int expectedNumberOfArguments = 6;
			if (args.Length != expectedNumberOfArguments)
				throw new Exception(string.Format("Insufficient number of arguments ({0} as opposed to {1}) specified for FinancialSummary load",
					args.Length, expectedNumberOfArguments));

			financialSummaryMap.Clear();
			SearchCriteria searchCriteria = (SearchCriteria)args[0];
			string glPostAsOfDate = (string)args[1];
			includeIndirect = (bool)args[2];
			string sortColumn = (string)args[3];
			bool sortAscending = (bool)args[4];
			string sessionID = (string)args[5];

            if ((searchCriteria[Constants.ProjectStartDateKey] != null) && !IsDate(searchCriteria[Constants.ProjectStartDateKey]))
                throw new Exception("Project Start Date contains an invalid date.");

            if ((searchCriteria[Constants.ProjectEndDateKey] != null) && !IsDate(searchCriteria[Constants.ProjectEndDateKey]))
                throw new Exception("Project End Date contains an invalid date.");
					
            if ((searchCriteria[Constants.BudgetStartDateKey] != null) && !IsDate(searchCriteria[Constants.BudgetStartDateKey]))
                throw new Exception("Budget Start Date contains an invalid date.");

            if ((searchCriteria[Constants.BudgetEndDateKey] != null) && !IsDate(searchCriteria[Constants.BudgetEndDateKey]))
                throw new Exception("Budget End Date contains an invalid date.");

            if ((searchCriteria[Constants.ProjectEndFromKey] != null) && (searchCriteria[Constants.ProjectEndToKey] != null))
                if (DateTime.Compare(DateTime.Parse(searchCriteria[Constants.ProjectEndFromKey]), DateTime.Parse(searchCriteria[Constants.ProjectEndToKey])) > 0)
                    throw new Exception("Project End From Date cannot be after Project End To Date.");

            if ((searchCriteria[Constants.ProjectStartDateKey] != null) && (searchCriteria[Constants.ProjectEndDateKey] != null))
                if (DateTime.Compare(DateTime.Parse(searchCriteria[Constants.ProjectStartDateKey]), DateTime.Parse(searchCriteria[Constants.ProjectEndDateKey])) > 0)
                    throw new Exception("Project Start From Date cannot be after Project Start To Date.");

            if ((searchCriteria[Constants.BudgetStartDateKey] != null) && (searchCriteria[Constants.BudgetEndDateKey] != null))
                if (DateTime.Compare(DateTime.Parse(searchCriteria[Constants.BudgetStartDateKey]),DateTime.Parse(searchCriteria[Constants.BudgetEndDateKey])) > 0)
                    throw new Exception("Budget Start From Date cannot be after Budget Start To Date.");

            if ((searchCriteria[Constants.BudgetEndFromKey] != null) && (searchCriteria[Constants.BudgetEndToKey] != null))
                if (DateTime.Compare(DateTime.Parse(searchCriteria[Constants.BudgetEndFromKey]), DateTime.Parse(searchCriteria[Constants.BudgetEndToKey])) > 0)
                    throw new Exception("Budget End  From Date cannot be after Budget End To Date.");

			if (DataContainer != null)
				DataContainer.Dispose();
			
			DataContainer = DataAccess.GetDataSet(connectionString, "GetFundIDsAndTotals",
				DataAccess.BuildSqlParameterArray(
				"@lastGLPostDate", SqlDbType.DateTime, Convert.ToDateTime(glPostAsOfDate),
				"@glPostAsOfDate", SqlDbType.DateTime, Convert.ToDateTime(glPostAsOfDate),
				"@includeIndirect", SqlDbType.Bit, includeIndirect,
				"@SessionID", SqlDbType.VarChar,sessionID,
				"@domainUserId", SqlDbType.Int, searchCriteria[Constants.DomainUserIDKey],
				"@fundNumber", SqlDbType.VarChar, searchCriteria[Constants.FundIDKey],
				"@folderNumber", SqlDbType.VarChar, searchCriteria[Constants.FolderNumberKey],
				"@bicsNumber", SqlDbType.VarChar, searchCriteria[Constants.BicsNumberKey],
				"@walkerNumber", SqlDbType.VarChar, searchCriteria[Constants.WalkerNumberKey],
				"@sponsorNumber", SqlDbType.VarChar, searchCriteria[Constants.SponsorNumberKey],
				"@sponsorName", SqlDbType.VarChar, searchCriteria[Constants.SponsorNameKey],
				"@sponsorTypeId", SqlDbType.Int, searchCriteria[Constants.SponsorTypeIDKey],
				"@agreementTypeId", SqlDbType.Int, searchCriteria[Constants.AgreementTypeIDKey],
				"@activityCode", SqlDbType.VarChar, searchCriteria[Constants.ActivityCodeKey],
				"@locationId", SqlDbType.Int, searchCriteria[Constants.LocationIDKey],
				"@budgetStartDate", SqlDbType.DateTime, searchCriteria[Constants.BudgetStartDateKey],
				"@budgetEndDate", SqlDbType.DateTime, searchCriteria[Constants.BudgetEndDateKey],
                "@budgetEndFrom", SqlDbType.DateTime, searchCriteria[Constants.BudgetEndFromKey],
                "@budgetEndTo", SqlDbType.DateTime, searchCriteria[Constants.BudgetEndToKey],   
				"@projectStartDate", SqlDbType.DateTime, searchCriteria[Constants.ProjectStartDateKey],
				"@projectEndDate", SqlDbType.DateTime, searchCriteria[Constants.ProjectEndDateKey],
                "@projectEndFrom", SqlDbType.DateTime, searchCriteria[Constants.ProjectEndFromKey],
                "@projectEndTo", SqlDbType.DateTime, searchCriteria[Constants.ProjectEndToKey],
                "@projectTitle", SqlDbType.VarChar, searchCriteria[Constants.ProjectTitle],
				"@piName", SqlDbType.VarChar, searchCriteria[Constants.PIIDKey],
				"@chiefCodeList", SqlDbType.VarChar, searchCriteria.COSIds,
				"@sponsorGroupTypeId", SqlDbType.Int, searchCriteria[Constants.ViewingOptionKey],
				"@includeProgramProjects", SqlDbType.Bit, searchCriteria[Constants.IncludeProgramProjectsKey],
				"@daysBudgetEnding", SqlDbType.Int, searchCriteria[Constants.DaysBudgetEndingKey],
				"@daysProjectEnding", SqlDbType.Int, searchCriteria[Constants.DaysProjectEndingKey],
				"@daysFundCreated", SqlDbType.Int, searchCriteria[Constants.DaysFundCreatedKey],
				"@lowBalance", SqlDbType.Money, searchCriteria[Constants.BalanceGreaterThanKey],
				"@highBalance", SqlDbType.Money, searchCriteria[Constants.BalanceLessThanKey],
				"@agreementStatusTypeList", SqlDbType.VarChar, searchCriteria[Constants.AgreementStatusIDKey],
				"@fundStatusTypeId", SqlDbType.Int, searchCriteria[Constants.FundStatusIDKey],
				"@sortColumn", SqlDbType.VarChar, string.Format("{0} {1}", sortColumn,sortAscending ? Constants.SortViewAscending: Constants.SortViewDescending),
             	"@viewTypeId", SqlDbType.Int, searchCriteria[Constants.ViewType],
                "@documentId", SqlDbType.VarChar, searchCriteria[Constants.DocumentId]
                ));

			if (DataContainer.Tables.Count != 2)
				throw new Exception("Failed to load Financial Summary information.");
		}
		#endregion

		#region Depracterd Methods
		// This method MUST go away once the lazy-loading is implemented. It exists currently only to support the download functionality.
		public void DepracatedLoad(string connectionString, params object[] args)
		{				
			const int expectedNumberOfArguments = 4;
			if (args.Length != expectedNumberOfArguments)
				throw new Exception(string.Format("Insufficient number of arguments ({0} as opposed to {1}) specified for FinancialSummary load",
					args.Length, expectedNumberOfArguments));

			bool isDate = true;
			SearchCriteria searchCriteria = (SearchCriteria)args[0];

			string glPostAsOfDate = (args[1] == null) ? null : (string)args[1];
			bool includeIndirect  = (args[2] == null) ? false : (bool)args[2];

			string agreementstatusvalue = searchCriteria[Constants.AgreementStatusIDKey];

			if (searchCriteria[Constants.ProjectStartDateKey] != null) 
			{
				IsDate(searchCriteria[Constants.ProjectStartDateKey]);
				if (isDate == false)
					throw new Exception("Project Start Date Contains an Invalid Date");
			}
			if (searchCriteria[Constants.ProjectEndDateKey] != null)
				IsDate(searchCriteria[Constants.ProjectEndDateKey]);
			if (isDate == false)
				throw new Exception("Project End Date Contains an Invalid Date");
					
			if (searchCriteria[Constants.BudgetStartDateKey] != null)
				IsDate(searchCriteria[Constants.BudgetStartDateKey]);
			if (isDate == false)
				throw new Exception("Budget Start Date Contains an Invalid Date");

			if (searchCriteria[Constants.BudgetEndDateKey] != null)
				IsDate(searchCriteria[Constants.BudgetEndDateKey]);
			if (isDate == false)
				throw new Exception("Budget End Date Contains an Invalid Date");

			DataContainer = DataAccess.GetDataSet(connectionString, "GetAgreementSummaryExcelReport",
				DataAccess.BuildSqlParameterArray(
				"@lastGLPostDate", SqlDbType.DateTime, Convert.ToDateTime(glPostAsOfDate)
				,"@glPostAsOfDate", SqlDbType.DateTime, Convert.ToDateTime(glPostAsOfDate)
				,"@includeIndirect", SqlDbType.Bit, includeIndirect
				,"@domainUserId", SqlDbType.Int, searchCriteria[Constants.DomainUserIDKey]
				,"@fundNumber", SqlDbType.VarChar, searchCriteria[Constants.FundIDKey]
				,"@folderNumber", SqlDbType.VarChar, searchCriteria[Constants.FolderNumberKey]
				,"@bicsNumber", SqlDbType.VarChar, searchCriteria[Constants.BicsNumberKey]
				,"@walkerNumber", SqlDbType.VarChar, searchCriteria[Constants.WalkerNumberKey]
				,"@sponsorNumber", SqlDbType.VarChar, searchCriteria[Constants.SponsorNumberKey]
				,"@sponsorName", SqlDbType.VarChar, searchCriteria[Constants.SponsorNameKey]
				,"@sponsorTypeId", SqlDbType.Int, searchCriteria[Constants.SponsorTypeIDKey]
				,"@agreementTypeId", SqlDbType.Int, searchCriteria[Constants.AgreementTypeIDKey]
				,"@activityCode", SqlDbType.VarChar, searchCriteria[Constants.ActivityCodeKey]
				,"@locationId", SqlDbType.Int, searchCriteria[Constants.LocationIDKey]
				,"@budgetStartDate", SqlDbType.DateTime, searchCriteria[Constants.BudgetStartDateKey]
				,"@budgetEndDate", SqlDbType.DateTime, searchCriteria[Constants.BudgetEndDateKey]
				,"@projectStartDate", SqlDbType.DateTime, searchCriteria[Constants.ProjectStartDateKey]
				,"@projectEndDate", SqlDbType.DateTime, searchCriteria[Constants.ProjectEndDateKey]
				,"@piName", SqlDbType.VarChar, searchCriteria[Constants.PIIDKey]
				,"@chiefCodeList", SqlDbType.VarChar, searchCriteria.COSIds
				,"@sponsorGroupTypeId", SqlDbType.Int, searchCriteria[Constants.ViewingOptionKey]
				,"@includeProgramProjects", SqlDbType.Bit, searchCriteria[Constants.IncludeProgramProjectsKey]
				,"@daysBudgetEnding", SqlDbType.Int, searchCriteria[Constants.DaysBudgetEndingKey]
				,"@daysProjectEnding", SqlDbType.Int, searchCriteria[Constants.DaysProjectEndingKey]
				,"@daysFundCreated", SqlDbType.Int, searchCriteria[Constants.DaysFundCreatedKey]
				,"@lowBalance", SqlDbType.Money, searchCriteria[Constants.BalanceGreaterThanKey]
				,"@highBalance", SqlDbType.Money, searchCriteria[Constants.BalanceLessThanKey]
				,"@agreementStatusTypeList", SqlDbType.VarChar, searchCriteria[Constants.AgreementStatusIDKey]
				,"@fundStatusTypeId", SqlDbType.Int, searchCriteria[Constants.FundStatusIDKey]
				));

			if ( DataContainer.Tables.Count == 0 )
				throw new Exception("Failed to load Financial Summary information.");

			const string OriginalDataTableName = "original";
			DataContainer.Tables[0].TableName = OriginalDataTableName;

			DataView dataView = new DataView(DataContainer.Tables[OriginalDataTableName]);
//			dataView.Sort = String.Format("{0} {1}", SortColumn, SortAscending ? Constants.SortViewAscending: Constants.SortViewDescending);
			dataView.RowStateFilter = DataViewRowState.CurrentRows;

//			DataTable dataTable = dataView.Table.Clone();
//			dataTable.TableName = OriginalDataTableName;
//
//			foreach (DataRowView dataRowView in dataView)
//				dataTable.ImportRow(dataRowView.Row);
//
//			DataContainer.Tables.Remove(OriginalDataTableName);
//			DataContainer.Tables.Add(dataTable);

			DataTable totals = new DataTable("Totals");

			//Create the Totals by creating an in memory table with a column for each total.  Then
			//create a data row, compute the totals for each column in the row and add the row to the table.
			totals.Columns.Add(new DataColumn("TotalBudgetAmount", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalLastMoExpenses", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalExpensesToDate", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalBudgetBalance", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalRevenue", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalCurrentCashBalance", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalOpenPOAPBalance", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalPlannedSalary", System.Type.GetType("System.Decimal")));
			totals.Columns.Add(new DataColumn("TotalProjectedBalance", System.Type.GetType("System.Decimal")));

			if (dataView.Count > 0)
			{
				DataRow datarow = totals.NewRow();
				datarow["TotalBudgetAmount"]		= (decimal) dataView.Table.Compute("sum(totalBudgetAmount)",dataView.RowFilter);
				datarow["TotalLastMoExpenses"]		= (decimal) dataView.Table.Compute("sum(lastMoExpenses)",dataView.RowFilter);
				datarow["TotalExpensesToDate"]		= (decimal) dataView.Table.Compute("sum(expensesToDate)",dataView.RowFilter);
				datarow["TotalBudgetBalance"]		= (decimal) dataView.Table.Compute("sum(budgetBalance)",dataView.RowFilter);
				datarow["TotalRevenue"]				= (decimal) dataView.Table.Compute("sum(Revenue)",dataView.RowFilter);
				datarow["TotalCurrentCashBalance"]	= (decimal) dataView.Table.Compute("sum(CurrentCashBalance)",dataView.RowFilter);
				datarow["TotalOpenPOAPBalance"]		= (decimal) dataView.Table.Compute("sum(openPOAPBalance)",dataView.RowFilter);
				datarow["TotalPlannedSalary"]		= (decimal) dataView.Table.Compute("sum(plannedSalary)",dataView.RowFilter);
				datarow["TotalProjectedBalance"]	= (decimal) dataView.Table.Compute("sum(ProjectedBalance)",dataView.RowFilter);
				totals.Rows.Add(datarow);
			}

			DataContainer.Tables.Add(totals);			
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Get the set of fund information for a set of fund IDs bound by a start and end index. These indeces are into the list of fund IDs
		/// that was loaded during the Load() method execution into the data container. Typically, the start index
		/// is on a "page" boundary, where the "page" referes to a datagrid page.
		/// Note that the total number of fund information returned may be less than the requested count.
		/// We maintain a Hashtable of DataSet objects using the start index as the key. This allows us to retrieve the
		/// set of fund information associated with that index, thereby directly supporting random access based the
		/// page index.
		/// If such a DataSet does not exist for the current page index, we load it using the list of fund IDs.
		/// The start end end indeces into that list are computed based on the current page index and the datagrid page size.
		/// Fund information is loaded based on the IDs which falls within the computed start and end indeces.
		/// The list of fund IDs is passed along to the stored procedur for load within the XML for the containing dataset.
		/// For download functionality the start-index would be set to < 0. This allows us NOT to cache the resulting data.
		/// </summary>
		/// <param name="startIndex">Index within the fund ID list to begin at</param>
		/// <param name="count">Total number of fund information to load (< 0 for download functionality)</param>
		/// <returns>DataSet with the loaded fund information</returns>
		public DataSet GetFundInfo(int startIndex, int count)
		{
			DataSet summaries = financialSummaryMap[startIndex] as DataSet;
			if (summaries == null)
			{
				DataTable idTable = DataContainer.Tables[(int)TableIndex.IDs];
				DataTable dt = idTable.Clone();
				for (int i = startIndex < 0 ? 0 : startIndex, end = Math.Min(i + count, idTable.Rows.Count); i < end; ++i)
					dt.ImportRow(idTable.Rows[i]);
				DataSet ds = new DataSet();
				ds.Tables.Add(dt);

				summaries = DataAccess.GetDataSet(DataAccess.ConnectionString, "GetFinancialSummaryForFunds",
					DataAccess.BuildSqlParameterArray("@xml", SqlDbType.Text, ds.GetXml(),
					"@includeIndirect", SqlDbType.Int, includeIndirect));

				if (startIndex >= 0)
				{
					summaries.Tables[0].Columns.Add("AccessLevel");
					DataTable dataTable = DataContainer.Tables[(int)TableIndex.IDs];
					foreach (DataRow row in summaries.Tables[0].Rows)
					{
						object accessLevel = dataTable.Select(string.Format("FundID={0}", row["FundID"]))[0]["AccessLevel"];
						row["AccessLevel"] = Convert.ToInt32(accessLevel);
					}

					financialSummaryMap[startIndex] = summaries;
				}
			}
			return summaries;
		}
		#endregion
	}
	#endregion
}
// --- EOF ---